Subclass BigDb
BigDb is a database layer designed for extension, such that developers can build easy-to-use database libraries. Those libraries contain Orms, migrations, and stored queries.
Docs
- Sample Subclass
- Common BigDb methods to overridde
- Uncommon BigDb methods to override
Sample Subclass
You MUST subclass BigDb and define the namespace, or override the relevant methods. With this standard setup, a table like article
MUST map to Tlf\BigDb\Test\Orm\Article
. (simply ucfirst($table_name)
)
<?php
namespace Tlf\BigDb\Test;
class ArticlesDb extends \Tlf\BigDb {
protected string $orm_namespace = 'Tlf\\BigDb\\Test\\Orm';
// You can make this public if you want it changeable in code
protected string $db_name = 'tlf_articles';
/**
* Return the root directory that contains `orm`, `sql`, and `migrate` dirs.
* Overriding is optional
* Defaults to the directory this subclass is defined in.
*/
public function get_root_dir(): ?string {
return __DIR__.'/db/';
}
}
Tip: Override public function get_orm_namespace(): string
or public function get_orm_class(string $table): string
Common BigDb methods to overridde
-
public function get_root_dir(): ?string
- Override this if your BigDb subclass is NOT at the root dir of your library. -
public function get_orm_class(string $table): string
- Override if thenamespace
+ucfirst($table_name)
mappings will not work for you. -
public function get_migration_dir(): string
- Override if your migration dir is not at yourroot_dir/migrate/
-
public function get_migration_vars(): array
- Override to make additional vars available to your library's migrations. Default passes['db'=>$this]
, soup.php
anddown.php
scripts have access to the BigDb instance via the variable$db
.
Uncommon BigDb methods to override
-
public function migrate(int $version_from, int $version_to)
- Override to use a different migration scheme than LilDb's LilMigrations class -
public function init_sql()
- override to use a different sql storage system than LilDb's LilSql. If you do this, set statements to$this->sql[$query_key] = 'SOME SQL STATEMENT';
, and you would probably want to overriderecompile_sql()
as well. -
insert(...)
, update, delete, select - You can override these if you don't want to use LilDb as a backend. -
public function row_to_orm(string $table, array $row): \Tlf\BigOrm